<?php

namespace App\Libs;

/**
 * 做一些和反射机制有关的处理
 * Class ClassArr
 * @package App\Libs
 */
class ClassArr
{
    public function uploadClassStat()
    {
        return [
            'image' => '\App\Libs\Upload\Image',
            'video' => '\App\Libs\Upload\Video',
        ];
    }

    /**
     * @param $type
     * @param $supportedClass
     * @param array $params
     * @param bool $needInstance
     * @return bool|object
     * @throws \ReflectionException
     */
    public function initClass($type, $supportedClass, $params = [], $needInstance = true)
    {
        if (!array_key_exists($type, $supportedClass)) {
            return false;
        }

        $className = $supportedClass[$type];

        return $needInstance ? (new \ReflectionClass($className))->newInstanceArgs($params) : $className;
    }
}